package com.dididoctor.patient.Activity.Usercentre.Evaluate;

import android.view.View;
import android.widget.AbsListView;
import android.widget.LinearLayout;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.MV.EduActivity;
import com.dididoctor.patient.R;
import com.dididoctor.patient.Ui.customlistview.OnRefreshListener;
import com.dididoctor.patient.Ui.customlistview.RefreshListView;
import com.dididoctor.patient.Utils.MyToast;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： UserEvaluateActivity
 * @包名称： com.dididoctor.patient.Activity.Usercentre.Evaluate
 * @创建人： zhanjunjie
 * @创建时间：2016/4/5 11:18
 * @修改人：
 * @修改时间：2016/4/5 11:18
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class UserEvaluateActivity extends EduActivity implements UserEvaluateView {

    private RefreshListView listView;
    private UserEvaluateAdapter adapter;
    private UserEvaluatePresenter presenter;
    private int pageIndex = 1;
    private List<UserEvaluate> evaluates = new ArrayList<>();
    private LinearLayout ll_on_order;

    @Override
    public void init() {
        setText(R.id.tv_title, "我的评价");
        listView = (RefreshListView) findViewById(R.id.listview);
        ll_on_order = (LinearLayout) findViewById(R.id.ll_on_order);
        listView.setHeadAndFoot(true, true);
        listView.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onPullDownRefresh() {
                pageIndex = 1;
                presenter.getEvaluate(pageIndex);
            }

            @Override
            public void onLoadMoring() {
                pageIndex++;
                presenter.getEvaluate(pageIndex);
            }

            @Override
            public void onScrollListener(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });
        adapter = new UserEvaluateAdapter(this, evaluates);
        listView.setAdapter(adapter);
        presenter = new UserEvaluatePresenter(this, this);
        presenter.getEvaluate(pageIndex);
    }

    @Override
    public void onClickEvent(View view) {

    }

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_user_evaluate);
    }

    @Override
    public void getEvaluate(List<UserEvaluate> evaluates) {
        if (evaluates != null && evaluates.size() > 0) {
            //没有评价内容
            ll_on_order.setVisibility(View.GONE);
            listView.setVisibility(View.VISIBLE);
            if (pageIndex == 1) {
                this.evaluates.clear();
                adapter.setData(evaluates);
                listView.onRefreshFinish();
            }else{
                if (evaluates.size() < ConstantValue.LOAD_MESSAGE_COUNT) {
                    adapter.addData(evaluates);
                    listView.showNoMoreData();
                } else {
                    adapter.addData(evaluates);
                    listView.hideNoMoreData();
                }
            }
            adapter.notifyDataSetChanged();
        } else {
            if (pageIndex == 1) {
                ll_on_order.setVisibility(View.VISIBLE);
                listView.setVisibility(View.GONE);
            }else{
                listView.showNoMoreData();
                adapter.notifyDataSetChanged();
            }
        }
    }

    @Override
    public void getEvaluatefail() {
        listView.onRefreshFinish();
        MyToast.DefaultmakeText(UserEvaluateActivity.this,"您的网络异常请稍候再试！",0);
    }

    @Override
    public void getEvaluateno() {
        listView.onRefreshFinish();
    }
}
